﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import flash.events.*;
    import flash.display.*;

    public class MovieClipUtil {

        public static function recursiveStop(_arg1:DisplayObjectContainer):void{
            var _local2:*;
            if ((_arg1 is MovieClip)){
                (_arg1 as MovieClip).stop();
            };
            var _local3:Number = _arg1.numChildren;
            while (_local3--) {
                _local2 = _arg1.getChildAt(_local3);
                if (((_local2) && ((_local2 is DisplayObjectContainer)))){
                    MovieClipUtil.recursiveStop(_local2);
                };
            };
        }
        public static function recursivePlay(_arg1:DisplayObjectContainer):void{
            var _local2:*;
            if ((_arg1 is MovieClip)){
                (_arg1 as MovieClip).play();
            };
            var _local3:Number = _arg1.numChildren;
            while (_local3--) {
                _local2 = _arg1.getChildAt(_local3);
                if (((_local2) && ((_local2 is DisplayObjectContainer)))){
                    MovieClipUtil.recursivePlay(_local2);
                };
            };
        }
        public static function recursiveRewind(_arg1:DisplayObjectContainer):void{
            var _local2:*;
            if ((_arg1 is MovieClip)){
                (_arg1 as MovieClip).gotoAndStop(1);
            };
            var _local3:Number = _arg1.numChildren;
            while (_local3--) {
                _local2 = _arg1.getChildAt(_local3);
                if (((_local2) && ((_local2 is DisplayObjectContainer)))){
                    MovieClipUtil.recursiveRewind(_local2);
                };
            };
        }
        public static function playAndStop(_arg1:MovieClip, _arg2:int=1, _arg3:int=-1, _arg4:Boolean=false, _arg5:Function=null):void{
            var clip:* = _arg1;
            var startFrame:int = _arg2;
            var endFrame:int = _arg3;
            var fullStop:Boolean = _arg4;
            var callback = _arg5;
            if (endFrame < startFrame){
                endFrame = clip.totalFrames;
            };
            runWhenOnStage(clip, function ():void{
                clip.stage.addEventListener(Event.ENTER_FRAME, function (_arg1:Event):void{
                    if (clip.currentFrame >= endFrame){
                        if (clip.stage){
                            clip.stage.removeEventListener(Event.ENTER_FRAME, arguments.callee);
                            if (fullStop){
                                __slot1.recursiveStop(clip);
                            } else {
                                clip.stop();
                            };
                            if (callback != null){
                                callback();
                            };
                        };
                    };
                });
            });
            clip.gotoAndPlay(startFrame);
        }
        public static function playBackwardsAndStop(_arg1:MovieClip, _arg2:int=-1, _arg3:int=1, _arg4:Boolean=false, _arg5:Function=null):void{
            var clip:* = _arg1;
            var startFrame:int = _arg2;
            var endFrame:int = _arg3;
            var fullStop:Boolean = _arg4;
            var callback = _arg5;
            if (startFrame < endFrame){
                startFrame = clip.totalFrames;
            };
            runWhenOnStage(clip, function ():void{
                clip.stage.addEventListener(Event.ENTER_FRAME, function (_arg1:Event):void{
                    clip.gotoAndStop(startFrame);
                    if (clip.currentFrame <= endFrame){
                        if (clip.stage){
                            clip.stage.removeEventListener(Event.ENTER_FRAME, arguments.callee);
                            if (fullStop){
                                __slot1.recursiveStop(clip);
                            } else {
                                clip.stop();
                            };
                            if (callback != null){
                                callback();
                            };
                        };
                    };
                    startFrame--;
                });
            });
            clip.gotoAndPlay(startFrame);
        }
        public static function playAndRemove(_arg1:MovieClip, _arg2:int=1, _arg3:int=-1):void{
            var clip:* = _arg1;
            var startFrame:int = _arg2;
            var endFrame:int = _arg3;
            playAndStop(clip, startFrame, endFrame, false, function ():void{
                if (clip.parent != null){
                    clip.parent.removeChild(clip);
                };
            });
        }
        public static function makeOneShotClip(_arg1:Class, _arg2:DisplayObjectContainer, _arg3:int=1):MovieClip{
            var _local4:* = new (_arg1)();
            var _local5:MovieClip = (_local4 as MovieClip);
            if (!(_local5 is MovieClip)){
                throw (new Error(("Expected a movie clip, got: " + _local4)));
            };
            _arg2.addChild(_local5);
            playAndRemove(_local5, _arg3);
            return (_local5);
        }
        public static function runWhenOnStage(_arg1:DisplayObject, _arg2:Function):void{
            var clip:* = _arg1;
            var callback:* = _arg2;
            if (clip.stage != null){
                callback();
            } else {
                clip.addEventListener(Event.ADDED_TO_STAGE, function (_arg1:Event):void{
                    clip.removeEventListener(Event.ADDED_TO_STAGE, arguments.callee);
                    callback();
                });
            };
        }

    }
}//package Classes.util 
